package com.atguigu.myzhxy;

import java.security.PublicKey;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Longest {
//    有N个正整数组成的一个序列。给定整数sum，求长度最长的连续子序列，使他们的和等于sum，返回此子序列的长度，如果没有满足要求的序列，返回-1。

    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        String[] arr=sc.nextLine().split(",");
        int sum=sc.nextInt();
        int[] num=new int[arr.length];
        for (int i=0;i<arr.length;i++){
            num[i]=Integer.parseInt(arr[i]);
        }
        System.out.println(Lengthest(num,sum));
    }
    public static int Lengthest(int[] arr, int sum) {
        int lengthmax = -1;
        for (int j = 0; j < arr.length; j++) {
            int length = -1;
            int sum0 = 0;
            for (int i = j; i < arr.length; i++) {
                if (arr[i] > sum) {
                    break;
                } else if (arr[i] == sum && lengthmax == -1) {
                    lengthmax = 1;
                } else {
                    sum0 += arr[i];
                    if (sum0 == sum) {
                        length = i - j + 1;
                        if (lengthmax < length) {
                            lengthmax = length;
                        }
                        break;
                    } else if (sum0 > sum) {
                        break;
                    }
                }
            }
        }
    return lengthmax;
    }
}
